//-----------------------------------------------------
// staticguientity.cpp
//-----------------------------------------------------

/**
 * @file staticguientity.cpp
 */

#include "staticguientity.h"
#include "nguimanager.h"
#include <application/nGfxobject.h>

namespace nebulaGUI {

	NGUIStaticEntity::NGUIStaticEntity() : nebulaEntity(NULL)
	{
		nebulaEntity = new nGfxObject();
	}

	NGUIStaticEntity::~NGUIStaticEntity()
	{
		nebulaEntity->Unload();

		if (nebulaEntity)
			delete nebulaEntity;
	}

	bool NGUIStaticEntity::render()
	{
		if (nebulaEntity && visible)
		{
			nebulaEntity->Render();
			return true;
		}
	}

	bool NGUIStaticEntity::loadResource()
	{
		if (nebulaEntity)
			return nebulaEntity->Load();
		else
			return false;
	}

	void NGUIStaticEntity::unloadResource()
	{
		nebulaEntity->Unload();
	}

	bool NGUIStaticEntity::setResource(const char *nFile)
	{
		if (nebulaEntity)
		{
			nebulaEntity->SetResourceName(nFile);
			return true;
		}
		else
			return false;
	}

	void NGUIStaticEntity::positionChanged(const logic::CEntity *entity, const tools::CVector &pos)
	{
		if (nebulaEntity) 
		{
			transform44 mt = nebulaEntity->Transform();
			mt.settranslation(vector3(x, y, z));
			nebulaEntity->Transform().setmatrix(mt.getmatrix());
		}
		NGUIEntity::positionChanged(entity, pos);
	}


}; // namespace nebulaGUI